import 'package:dio_http_cache/dio_http_cache.dart';
import 'package:flutter_archer/data/entity/models.dart';
import 'package:flutter_archer/data/entity/request/login_request.dart';
import 'package:flutter_archer/data/entity/request/register_request.dart';
import 'package:flutter_archer/shared/services/network/app_http_transformer.dart';
import 'package:flutter_archer/shared/services/network/http_client.dart';
import 'package:flutter_archer/shared/services/network/http_response.dart';

class UserRemoteSource {
  UserRemoteSource({required this.apiProvider});

  final HttpClient apiProvider;

  Future<HttpResponse> login(LoginRequest data) async{
    return apiProvider.post(
        '/base/login',
      data: data,
      httpTransformer:AppHttpTransformer(fromJson: (val)=>LoginResponse.fromJson(val))
    );
  }

  Future<HttpResponse> register(RegisterRequest data) {
    return apiProvider.post(
      '/base/register',
        data: data,
        httpTransformer:AppHttpTransformer(fromJson: (val)=>RegisterResponse.fromJson(val))
    );
  }

  Future<HttpResponse> getUserInfo() {
    return apiProvider.get(
        '/user/getUserInfo',
        queryParameters: {"id": 2},
      options: buildCacheOptions(Duration(minutes: 5))
    );
  }
}